package com.tjetc.controller;


import com.tjetc.common.JsonResult;
import com.tjetc.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/province")
public class ProvinceController {
    @Autowired
    private AreaService areaService;

    /***
     * 查询所有的省
     * @return
     */
    @RequestMapping("all")
    public JsonResult getAllProvince(){
        return areaService.getAllChildByPid(1, 1);
    }

    /***
     * 根据省名称查询省id
     * @param name
     * @return
     */
    @RequestMapping("queryid/{name}")
    public JsonResult getProvinceByName(@PathVariable String name){
        return areaService.getAreaIdFromName(name, 1);
    }

    /***
     * 根据省id查询省名称
     * @param id
     * @return
     */
    @RequestMapping("queryname/{id}")
    public JsonResult getProvinceById(@PathVariable int id){
        return areaService.getAreaById(id, 1);
    }

}
